How to Check if a Binary File Has Been Updated in an SPItemEventReceiver

Comments 0

Share to social media

I’ve been dealing with a number of item event receivers in SharePoint and I ran across the need to figure out whether or not the binary file associated with an item in a document library is being updated during the ItemUpdating event.  I knew there were some additional events in the SPItemEventReceiver class, but it turns out that none of them alert you as to when a binary file is actually being updated. 

With the simple option out, I had to turn to a more investigative approach.  So I threw in some code to write out the BeforeProperties and AfterProperties of the properties parameter passed into the ItemUpdating method to see if there was some telltale sign of a binary file update, and there were a few.

So if you want to tell whether or not the binary file has been updated in the ItemUpdating method, you just have to check if vti_docstoreversion has a null value in the AfterProperties collection.  If it has a value, then the binary file has NOT been updated.

There are some additional properties for which this appears to hold true as well:

  • vti_docstoreversion
  • vti_docstoretype
  • vti_metainfoversion
  • vti_contentversionisdirty
  • vti_contenttag
  • vti_modifiedby
  • vti_timelastmodified

I’m not sure if they all always hold true, but they appeared to be consistent in what little testing I did.

Load comments

About the author

Damon Armstrong

See Profile

Damon Armstrong is a consultant with SystemwarePS in Dallas, Texas. He is also a blogger and author of Pro ASP.NET 2.0 Website Programming and SharePoint 2013 Essentials for Developers. He specializes in the Microsoft stack with a focus on web technologies like MVC, ASP.NET, JavaScript, and SharePoint. When not staying up all night coding, he can be found watching a bunch of kids, studying Biblical topics, playing golf, or recovering from staying up all night coding.